var appPath = getAppPath();	

$(function(){
	initJspGrid();
});

// 自定义动画列表初始化
function initJspGrid(){
	
	$('#videoUdocGrid').datagrid({
	    url:appPath + "/yjxCust/getCustVideoDoc.action",
	    height:'full',
	    striped:true,
	    fitColumns:true,
	    queryParams: getQueryParam(),
	    singleSelect:false,
		checkbox:false,
	    columns:[[
	        {field:'doc_id',title:'作品ID',width:25,align:'center',sortable:false}, 
	        {field:'uni_doc_id',title:'统一作品ID',width:30,align:'center',sortable:false}, 
	        {field:'doc_name',title:'作品名称',width:40,align:'center',sortable:true},
	        {field:'user_id',title:'用户ID',width:25,align:'center',sortable:true},
	        {field:'custAniIds',title:'DataJSON',width:30,align:'center',sortable:true,
	        	formatter:function(value,rowData,rowIndex){ 	// c.tmpl_json, c.tmpl_set
	        		return '<a href="javascript:void(0)" onclick="showData('+rowData.uni_doc_id+')">查看</a>';
	        	}
	        },
	        {field:'create_time',title:'创建时间',width:60,align:'center',sortable:true},
	        {field:'update_time',title:'修改时间',width:60,align:'center',sortable:true}
	    ]],
	    hideColumn:['user_type'],
	    pagination:true,
		rownumbers:true
	});
}

function showData(uniDocId){
	$("#tmplJsonTxt").val('');
	$.loading(true);
	var url = appPath + "/yjxCust/getOneCustVideoUserDoc.action?uniDocId="+uniDocId;// 请求获取tmplJson数据
	$.post(url,function(ret){
		if (ret){
			$.loading(false);
			var info = ret[0];
			$("#vDataTxt").val(info.v_data);
			$("#tmplJsonTxt").val(info.tmpl_json);
		} else {
			$.loading(false);
		}
	});
	$('#tempData').window({
		title:'自由创建作品数据',
		iconCls:'icon-tip',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	$('#tempData').window('move',{top:20,left:20});
	$('#tempData').window('open');
}





// 判断是否是JSON文件
function isJSON(str) {
    if (typeof str == 'string') {
        try {
            var obj=JSON.parse(str); // 从字符串中解析出 json对象
            if(str.indexOf('{')>-1){
                return true;
            }else{
                return false;
            }

        } catch(e) {
            console.log(e);
            return false;
        }
    }
    return false;
}

function getQueryParam(){
	var queryObject = {};
	var findDocName = $("#queryName").val();// 
	var findDocId = $("#queryDocId").val();
	var findUniDocId = $("#queryUniDocId").val();
	if(findDocName && findDocName.length>0) queryObject.findDocName = findDocName;// 
	if (Number(findDocId)>0) queryObject.findDocId = findDocId;
	if (Number(findUniDocId)>0) queryObject.findUniDocId = findUniDocId;
	return queryObject;
}

/*  查询数据
 */
function doQuery(){
	$("#videoUdocGrid").datagrid('unselectAll');
	$("#videoUdocGrid").datagrid('load',getQueryParam());
}
